<include file="Public/mobile_head"/>
<link href="__STATIC__/shop_mobile/common.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
	
<meta charset="utf-8">
<script language="javascript" src="{:ADDON_PUBLIC_PATH}/js/calendar/jquery-1.12.0.js"></script>

<body>
    <div class="container" align="left">
		<php> $post_url || $post_url = U('edit?id='.$vo['id'], $get_param);</php>
    	<form action="{:$post_url}" id="subform" method="post">
            <div class="address_form">
			
				<div class="addressItem" style="position:static">
					<h2 style="font-size: 1.5em;"> 新增/修改 节日</h2>
				</div>
			
				
				<!-- 名称 -->
            	<div class="addressItem tb">
                    <label for="truename" class="flex_2">节日名称</label>
                    <div class="flex_1">
						<input type="text" name="remind_title" id="remind_title" value="{$vo.remind_title}" placeholder="结婚纪念日" class="span3" required>
                    </div>
                </div>
				
				<!-- 类型 -->
				<div class="addressItem tb">
                    <label for="is_use" class="flex_2">节日类型</label>
                    <div class="flex_1"> 
						<label class="radio"><input type="radio" name="recycle" value="1" id="year_recycle" onchange="changeDay('y')" 
							<eq name="vo[recycle]" value="1">checked="checked"</eq>  />周年</label>
		
						<label class="radio"><input type="radio" name="recycle" value="2" id="month_recycle" onchange="changeDay('m')"
							<eq name="vo[recycle]" value="2">checked="checked"</eq>  />月度</label>
					
						<label class="radio"><input type="radio" name="recycle" value="3" id="once_recycle" onchange="changeDay('d')"
							<eq name="vo[recycle]" value="3">checked="checked"</eq>  />单次</label>
                    </div>
                </div>
				

				<!-- 日期 -->
				<div class="addressItem tb">
					<label for="mobile" class="flex_2">节日日期</label>
					<div class="flex_1"> 
						<select id="time_year" style="display:inline-block; width:30%; align:right;" name="remind_year">
						</select>
						
						<select id="time_month" style="display:inline-block; width:30%; align:right;" name="remind_month">
						</select>
						
						<select id="time_day" style="display:inline-block;  width:33%; align:right;" name="remind_day">
						</select>
					</div>
				</div>
				
				<!-- 公历农历 -->
				<div class="addressItem tb">
                    <label for="is_use" class="flex_2">节日历法</label>
                    <div class="flex_1">
						<label class="radio"><input type="radio" name="date_format" value="0" id="date_format_0" 
							<eq name="vo[date_format]" value="0">checked="checked"</eq>  />公历</label>
		
						<label class="radio"><input type="radio" name="date_format" value="1" id="date_format_1"
							<eq name="vo[date_format]" value="1">checked="checked"</eq>  />农历</label>
                    </div>
                </div>
				
				<!-- 公历农历 -->
				<div class="addressItem tb" id="remind_set_div">
					<label for="mobile" class="flex_2" id="remind_set_label">提醒设置</label>
					<div class="flex_1"> 
						<select id="remind_set" name="remind_set" style="display:inline-block; width:100%; align:right;" onchange="change_remind_set()">
							<option value="-1">不提醒</option>
							<option value="0">当天提醒</option>
							<option value="1">提前一天提醒</option>
							<option value="7">提前一周提醒</option>
						</select>
					</div>
				</div>
				
				<!-- 提醒时间 -->
				<div class="addressItem tb"  id="remind_set_time_div">
					<label for="mobile" class="flex_2">提醒日期</label>
					<div class="flex_1"> 
						<select id="remind_set_time" name="remind_set_time" style="display:inline-block; width:100%; align:right;">
						</select>
					</div>
				</div>
				
				<!-- 描述 -->
                <div class="addressItem tb">
                    <label for="mobile" class="flex_2">节日描述</label>
                    <div class="flex_1">
						<input type="text" value="{$vo.remind_desc}" name="remind_desc" id="day_desc" />
                    </div>
                </div>
                         
            </div>
   			<div class="m_15" style="position:static">
                <notempty name="info.id"><input type="hidden" name="id" value="{$info.id}" /></notempty>
                <input type="hidden" name="from" value="{:I('from')}"/>
                <button class="btn" type="submit" onclick="return submit_dt()">保存</button>
            </div>
			
			<div class="addressItem tb" style="position:static">
				<font size="3" color="#919191" style="font-style:italic;"> 数据永久保存在云端服务器，不用担心丢失 </font>
			</div>
			
        </form>
    </div>	

<script type="text/javascript">

window.onload = function(){
    // 初始化年月日
    for(i=1980; i<2050; i++)
        $("#time_year").append("<option value=\"" + i + "\">"  + i + "年 </option>");
    $("#time_year").val("{$vo.remind_year}");    // 暂时不取本地时间了
	
    for(i=1; i<13; i++)
        $("#time_month").append("<option value=\"" + i + "\">" + i + "月 </option>");
    $("#time_month").val("{$vo.remind_month}");    // 暂时不取本地时间了
    
    for(i=1; i<32; i++)
        $("#time_day").append("<option value=\"" + i + "\">" + i + "日 </option>");
    $("#time_day").val("{$vo.remind_day}");    // 暂时不取本地时间了
    
	// 初始化小时
	for(i=0; i<24; i++)
        $("#remind_set_time").append("<option value=\"" + i + "\">" + i + "点 ~ " + (i+1) + "点 </option>");
    $("#remind_set_time").val("{$vo.remind_set_time}");
	
	
	var recycle = "{$vo.recycle}";
	// 初始化周年纪念类型
	switch(recycle)
	{
		case '2': changeDay('m');	break;
		case '3': changeDay('d');	break;
		default:  changeDay('y');
	}
	
	// 如果有标题，说明是edit，则禁止编辑标题
	var hasTitle = "{$vo.remind_title}";
	if(hasTitle != "")
	{
		$("#remind_title").attr('readonly', true);
	}
	
	$("#remind_set").val("{$vo.remind_set}");
	
	// TODO. 提醒时间和设置先隐藏，用默认值
	//$("#remind_set_div").hide();
	//$("#remind_set_time_div").hide();
	// TODO END
	
	change_remind_set();
}

function changeDay(kind) {
    $("#time_year").show();
    $("#time_month").show();
    $("#time_day").show();
    
    if(kind=="y") {
        $("#time_year").hide();
    }
    else if(kind=="m") {
        $("#time_year").hide();
        $("#time_month").hide();
    }
}

function change_remind_set() {
	var remind_set = $("#remind_set").val();
	if(remind_set == -1) {
		$("#remind_set_time").css('color', '#545454')
		$("#remind_set_time").attr('disabled', true);
	} else {
		$("#remind_set_time").css('color', 'black')
		$("#remind_set_time").removeAttr('disabled');
	}
}

function submit_dt() {
	var format = $("input:radio[name='date_format']:checked").val();
	var recycle = $("input:radio[name='recycle']:checked").val();
	
	var year = parseInt($("#time_year").val(), 10);
    var month = parseInt($("#time_month").val(), 10);
    var day  = parseInt($("#time_day").val(), 10);
	
	if(((year<1980||year>2050) && recycle=='3')
	|| ((month<1||month>12) && (recycle=='2'||recycle=='3'))
	|| (day<1||day>31))
	{
		alert("请正确填写日期");
		return false;
	}
    
    if(format=='0') {  // 公历
        if(month==2 && day > 29) {
            alert("2月日期不应该超过29日，请重新选择。");
			return false;
		}
        else if ((month==4||month==6||month==9||month==11) && day>30){
            alert("4、6、9、11月的日期不能大于30日，请重新选择。");
			return false;
        }
    }
    else {  // 阴历
        if(day>30) {
			alert("农历的日期设置不应该超过30日");
			return false;
		}
    }
    
    if($("#remind_title").val() == "") {
        alert("请输入节日名称");
        return false; 
    }
    
	
    $("#subform").submit();
}
</script>

</body>
</html>
